import { Component, OnInit, ViewChild, TemplateRef, Input } from '@angular/core'
import { FormBuilder, FormGroup } from '@angular/forms'
import { I18NService } from '@core'
import { NzMessageService } from 'ng-zorro-antd'
import { StoreDataService } from 'app/routes/store/store-data.service'
import { StoreNewBaseClass } from '../../../baseClass'
import { IOption } from '@shared/interfaces/common'
import { ESettleType, SettleTypeMap } from '@shared/interfaces/store'
import { HelperService } from '@shared/services/helper.service'


@Component({
  selector: 'app-store-new-settlement-period-config',
  templateUrl: './period-config.component.html',
})
export class CombSettlementPeriodConfigComponent extends StoreNewBaseClass implements OnInit {
  @Input() group: FormGroup

  settleTypeOptions: IOption[] = []
  disabled = true
  min = 1
  max = 14
  step = 1
  precision = 0
  constructor(
    public fb: FormBuilder,
    public storeService: StoreDataService,
    private i18n: I18NService,
    private msg: NzMessageService,
    private helperService: HelperService,
  ) {
    super(fb, storeService)
  }
  ngOnInit() {
    this.initSettleTypeOptions()
  }

  pushDataToStore() {}

  onChange(settleType: ESettleType) {
    switch (settleType) {
      case ESettleType.T1:
        this.disabled = true
        this.group.get('settleCycleDays').setValue(1)
        break

      case ESettleType.Delay:
        this.disabled = false
        break

      case ESettleType.AddUp:
        this.disabled = false
        break
    }
  }


  trans(key: string, params?: Object): string {
    return this.i18n.fanyi(key, params)
  }

  private initSettleTypeOptions(): void {
    this.settleTypeOptions = this.helperService.generateOptionsFromEnum(SettleTypeMap)
  }
}
